package md.lanjing.com.module_deal_center.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lxh.baselibray.mvp.MvpActivity;
import com.lxh.baselibray.net.ServiceGenerator;
import com.lxh.baselibray.util.ObjectUtils;
import com.lxh.baselibray.util.ToastUtils;
import com.lxh.baselibray.view.TitleView;

import butterknife.BindView;
import butterknife.OnClick;

import md.lanjing.com.module_deal_center.R;
import md.lanjing.com.module_deal_center.R2;
import md.lanjing.com.module_deal_center.bean.PayMoneyDetailResponce;
import com.lxh.baselibray.constant.Constant;
import md.lanjing.com.module_deal_center.contact.PayMoneyDetailContact;
import retrofit2.Response;

/**
 * 具体的支付方式-支付宝、微信、银行卡
 */
public class PayMoneyDetailActivity extends MvpActivity<PayMoneyDetailContact.PayMoneyDetailPresent> implements PayMoneyDetailContact.IPayMoneyDetailView{
    public static final String BILL_ID = "billId";
    public static final String TRANSFER_ID="transfer_id";
    @BindView(R2.id.titleView)
    TitleView titleView;
    @BindView(R2.id.iv_pay_code)
    ImageView ivPayCode;
    @BindView(R2.id.tv_card_name)
    TextView tvCardName;
    @BindView(R2.id.tv_card_num)
    TextView tvCardNum;
    @BindView(R2.id.tv_consign_name)
    TextView tvConsignName;
    @BindView(R2.id.linear_bank_pay)
    LinearLayout linearBankPay;

    public static String PAY_TYPE="payType";
    int payType;
    String type;
    String billId;
    String transferId;
    @Override
    public void initData(Bundle savedInstanceState) {
        payType = getIntent().getIntExtra(PAY_TYPE,0);
        billId=getIntent().getStringExtra(BILL_ID);
        transferId=getIntent().getStringExtra(TRANSFER_ID);
        switch (payType){
            case 0:
                type="aliPay";
                ivPayCode.setVisibility(View.VISIBLE);
                linearBankPay.setVisibility(View.GONE);
                ivPayCode.setImageResource(R.drawable.ali_pay_code);
                titleView.setTitleText("支付宝付款");
                break;
            case 1:
                type="wechat";
                ivPayCode.setVisibility(View.VISIBLE);
                linearBankPay.setVisibility(View.GONE);
                ivPayCode.setImageResource(R.drawable.weixin_pay_code);
                titleView.setTitleText("微信付款");
                break;
            case 2:
                type="bank";
                ivPayCode.setVisibility(View.GONE);
                linearBankPay.setVisibility(View.VISIBLE);
                titleView.setTitleText("银行卡付款");
                break;
        }
        mPresent.queryPayMoneyMsg(context,billId,type);
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_pay_money_detail;
    }


    @OnClick(R2.id.btn_up_deal_voucher)
    public void onViewClicked() {
        Intent intent = new Intent(this, DealVoucherActivity.class);
        intent.putExtra(DealVoucherActivity.TRANSFER_ID,transferId);
        intent.putExtra(DealVoucherActivity.PAYMENT,type);
        startActivity(intent);
    }

    @Override
    public void getPayMoneyDetailMsgData(Response<PayMoneyDetailResponce> response) {
        if (response.body().getCode()== Constant.SUCCESS_CODE){
            PayMoneyDetailResponce.DataBean data = response.body().getData();
            if (ObjectUtils.isEmpty(data))return;
            switch (payType){
                case 0:
                    Glide.with(context).load(ServiceGenerator.BASE_URL+":8089/image/"+data.getAliPay()).into(ivPayCode);
                    break;
                case 1:
                    Glide.with(context).load(ServiceGenerator.BASE_URL+":8089/image/"+data.getWeChat()).into(ivPayCode);
                    break;
                case 2:
                    tvCardName.setText(data.getBankName());
                    tvCardNum.setText(data.getCardNum());
                    tvConsignName.setText("持卡人姓名:"+data.getOwnerName());
                    break;
            }
        }else {
            ToastUtils.showLongToast(context,response.body().getMsg());
        }
    }

    @Override
    protected PayMoneyDetailContact.PayMoneyDetailPresent createPresent() {
        return new PayMoneyDetailContact.PayMoneyDetailPresent();
    }
}
